from selenium.webdriver.common.by import By
from selenium import webdriver
import time
from webdriver_manager.chrome import ChromeDriverManager
from pom import BasePage

# driver = webdriver.Chrome(ChromeDriverManager().install())
# url = "https://ssov2.t.dingdongxiaoqu.com/login?app_id=522"
# driver.get(url)
# img = driver.find_element(By.XPATH,'//*[@id="app"]/div/div[2]/div/div[3]/div[1]/div/img')
# print(img)
# img.click()
# time.sleep(5)

# 一个页面一个对象
# 页面公共部分，也封装成一个page
class LoginPage(BasePage):
    switch_img = (By.XPATH,'//*[@id="app"]/div/div[2]/div/div[3]/div[1]/div/img')
    hc_username = (By.XPATH,'//*[@id="app"]/div/div[2]/div/div[3]/div[3]/span[1]/div/input')
    hc_password = (By.XPATH,'//*[@id="app"]/div/div[2]/div/div[3]/div[3]/span[2]/div/input')
    hc_button = (By.XPATH,'//*[@id="app"]/div/div[2]/div/div[3]/div[3]/span[3]/div')

    def __init__(self):
        super().__init__()


    def switch_click(self):
        super().base_click(self.switch_img)

    # 定义一个页面能做什么，函数
    def login(self,username,password):
        """
        给哪个元素发送信息，点击哪个元素
        :param username:
        :param password:
        :return:
        """
        super().base_send_keys(self.hc_username,username)
        super().base_send_keys(self.hc_password,password)
        super().base_click(self.hc_button)
        time.sleep(3)

if __name__ == '__main__':
    lp = LoginPage()
    request_url = "https://ssov2.t.dingdongxiaoqu.com/login?app_id=522"
    lp.get(request_url)
    lp.switch_click()
    lp.login(username="17621543877",password="Tzz082701*")